#ifndef _QMC5883_H
#define _QMC5883_H

#include <stdint.h>
#include <stddef.h>

#define QMC5883_I2C_ADDRESS     0x2C

#define QMC5883_REG_XDATA_LSB   0x01
#define QMC5883_REG_XDATA_MSB   0x02
#define QMC5883_REG_YDATA_LSB   0x03
#define QMC5883_REG_YDATA_MSB   0x04
#define QMC5883_REG_ZDATA_LSB   0x05
#define QMC5883_REG_ZDATA_MSB   0x06

#define QMC5883_REG0_CONFIG     0x0A
#define QMC5883_REG1_CONFIG     0x0B

#define QMC5883_REG_FRB         0x29

#define QMC5883_CHIP_ID         0x00

#define QMC5883_MODE_Suspend    0x00
#define QMC5883_MODE_Normal     0x01
#define QMC5883_MODE_Single     0x02
#define QMC5883_MODE_Continuous 0x03

#define QMC5883_ODR_10HZ        0x00
#define QMC5883_ODR_50HZ        0x01
#define QMC5883_ODR_100HZ       0x02
#define QMC5883_ODR_200HZ       0x03

#define QMC5883_RNG_2G          0x00
#define QMC5883_RNG_8G          0x01
#define QMC5883_RNG_16G         0x02
#define QMC5883_RNG_30G         0x03

#define QMC5883_OSR1_8         0x00
#define QMC5883_OSR1_4         0x01
#define QMC5883_OSR1_2         0x02
#define QMC5883_OSR1_1         0x03

#define QMC5883_OSR2_8         0x03
#define QMC5883_OSR2_4         0x02
#define QMC5883_OSR2_2         0x01
#define QMC5883_OSR2_1         0x00

#define QMC5883_INTTERPUT_DISABLE   0x00
#define QMC5883_INTTERPUT_ENABLE    0x01

#define QMC5883_ROLL_NORMAL     0x00
#define QMC5883_ROLL_ENABLE     0x01

#define QMC5883_SETRESET_ON         0x00
#define QMC5883_SETRESET_SETON      0x01
#define QMC5883_SETRESET_OFF        0x02
#define QMC5883_SETRESET_OFF1        0x03

#define QMC5883_SELFTEST_DISABLE   0x00
#define QMC5883_SELFTEST_ENABLE    0x01

#define QMC5883_SOFTRESET_DISABLE   0x00
#define QMC5883_SOFTRESET_ENABLE    0x01

typedef union 
{
    uint8_t configs;
    struct{ 
        uint8_t mode : 2;
        uint8_t ODR : 2;
        uint8_t OSR1 : 2;
        uint8_t OSR2 : 2;
    } ;
}QMC5883_REG0_MODE;

typedef union 
{
    uint8_t configs;
    struct{ 
        uint8_t SET_RESET_MODE : 2;
        uint8_t RNG : 2;
        uint8_t RES : 2;
        uint8_t SELF_TEST : 1;
        uint8_t SOFT_RST : 1;
    } ;
}QMC5883_REG1_MODE;


int8_t qmc5883_user_i2c_init(void);
uint8_t qmc5883_init(void);
void QMC5883_get_data(void);
void QMC5883_ThreadStart(void);

#endif
